/*
============================================================================
 Name		: variasVentanasContainer.cpp
 Author	  : Ignacio Lopez
 Copyright   : GPL
 Description : Container control implementation
============================================================================
*/

// INCLUDE FILES
#include "FindMe2ndContainerStatus.h"
#include "Common.h"
#include <eiklabel.h>  // for example label control
#include "CConfig.h"

_LIT(KNodeid, "Device id: ");
_LIT(KGpsLabel, "GPS: ");
_LIT(KGprsLabel, "GPRS: ");
_LIT(KIntervalLabel, "Interval(secs): ");
_LIT(KStatusLabel, "Status: ");



// ================= MEMBER FUNCTIONS =======================

// ---------------------------------------------------------
// CFindMe2ndContainerStatus::ConstructL(const TRect& aRect)
// EPOC two phased constructor
// ---------------------------------------------------------
//
void CFindMe2ndContainerStatus::ConstructL(const TRect& aRect)
	{
	CreateWindowL();		

	CConfig* config = CConfig::NewL(KConfigFile);
	CleanupStack::PushL(config);
	TBuf<64> text;

	config->get_nodeIdL(text);
	text.Insert(0, KNodeid);
	iNodeid = new (ELeave) CEikLabel;
	iNodeid->SetContainerWindowL( *this );
	iNodeid->SetTextL( text );
	
	config->get_gps_nameL(text);
	text.Insert(0, KGpsLabel);
	iGps = new (ELeave) CEikLabel;
	iGps->SetContainerWindowL( *this );
	iGps->SetTextL( text );
	
	config->get_GprsNameL(text);
	text.Insert(0, KGprsLabel);
	iGprs = new (ELeave) CEikLabel;
	iGprs->SetContainerWindowL( *this );
	iGprs->SetTextL( text );
	
	config->get_intervalL(text);
	text.Insert(0, KIntervalLabel);
	iInterval = new (ELeave) CEikLabel;
	iInterval->SetContainerWindowL( *this );
	iInterval->SetTextL( text );
	
	text.Copy(_L("Idle"));
	text.Insert(0, KStatusLabel);
	iStatus = new (ELeave) CEikLabel;
	iStatus->SetContainerWindowL( *this );
	iStatus->SetTextL( text );
	
	CleanupStack::Pop(config);
	delete config;
	config = NULL;
	SetRect(aRect);
	ActivateL();
	}

// Destructor
CFindMe2ndContainerStatus::~CFindMe2ndContainerStatus()
	{
	delete iGps;
	delete iGprs;
	delete iInterval;
	delete iStatus;
	delete iNodeid;
	}

// ---------------------------------------------------------
// CFindMe2ndContainerStatus::SizeChanged()
// Called by framework when the view size is changed
// ---------------------------------------------------------
//
void CFindMe2ndContainerStatus::SizeChanged()
	{
	// TODO: Add here control resize code etc.
	iStatus->SetExtent( TPoint(5,5), iStatus->MinimumSize() );
	iGps->SetExtent( TPoint(5,25), iGps->MinimumSize() );
	iGprs->SetExtent( TPoint(5,45), iGprs->MinimumSize() );
	iInterval->SetExtent( TPoint(5,65), iInterval->MinimumSize() );
	iNodeid->SetExtent( TPoint(5,85), iNodeid->MinimumSize() );
	}

// ---------------------------------------------------------
// CFindMe2ndContainerStatus::CountComponentControls() const
// ---------------------------------------------------------
//
TInt CFindMe2ndContainerStatus::CountComponentControls() const
	{
	return 5; // return nbr of controls inside this container
	}

// ---------------------------------------------------------
// CFindMe2ndContainerStatus::ComponentControl(TInt aIndex) const
// ---------------------------------------------------------
//
CCoeControl* CFindMe2ndContainerStatus::ComponentControl(TInt aIndex) const
	{
	switch ( aIndex )
		{
		case 0:
			return iGps;
		case 1:
			return iGprs;
		case 2:
			return iInterval;
		case 3:
			return iStatus;
		case 4:
			return iNodeid;
		default:
			return NULL;
		}
	}

// ---------------------------------------------------------
// CFindMe2ndContainerStatus::Draw(const TRect& aRect) const
// ---------------------------------------------------------
//
void CFindMe2ndContainerStatus::Draw(const TRect& aRect) const
	{
	CWindowGc& gc = SystemGc();
	// TODO: Add your drawing code here
	// example code...
	gc.SetPenStyle( CGraphicsContext::ENullPen );
	gc.SetBrushColor( KRgbWhite );
	gc.SetBrushStyle( CGraphicsContext::ESolidBrush );
	gc.DrawRect( aRect );
	}

// ---------------------------------------------------------
// CFindMe2ndContainerStatus::HandleControlEventL(
//	 CCoeControl* aControl,TCoeEvent aEventType)
// ---------------------------------------------------------
//
void CFindMe2ndContainerStatus::HandleControlEventL(
	CCoeControl* /*aControl*/,TCoeEvent /*aEventType*/)
	{
	// TODO: Add your control event handler code here
	}

void CFindMe2ndContainerStatus::DisplayLabel(const enum TDisplaySection& aSection, const TDesC& aText) 
	{
		TBuf<MAXLENTEXTODISPLAY> message;
		if (aText.Length() > MAXLENTEXTODISPLAY)
			message.Copy(aText.Left(MAXLENTEXTODISPLAY));	
		else
			message.Copy(aText);
		
		TBuf<64> text; /* I think is enough */
		switch (aSection)
		{
			case ENodeid:
				text.Copy(KNodeid);
				text.Append(message);
				iNodeid->SetTextL(text);
				break;
			case EGps:
				text.Copy(KGpsLabel);
				text.Append(message);
				iGps->SetTextL(text);
				break;
			case EGprs:
				text.Copy(KGprsLabel);
				text.Append(message);
				iGprs->SetTextL(text);
				break;
			case EInterval:
				text.Copy(KIntervalLabel);
				text.Append(message);
				iInterval->SetTextL(text);
				break;
			case EStatus:
				text.Copy(KStatusLabel);
				text.Append(message);
				iStatus->SetTextL(text);
				break;
			default:
				break;
		}
		SizeChanged();
		DrawNow();
	}
